package com.itheima.controller;

import com.itheima.Service.UserService;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.pojo.UserQueryParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    //查询用户信息
    @GetMapping
    private Result Inquire(UserQueryParam userQueryParam){
        PageBean pageBean = userService.Inquire(userQueryParam);
        return Result.success(pageBean);
    }

    //删除用户（批量删除）
    @DeleteMapping
    private Result deleteUser(@RequestParam List<Integer> ids){
        log.info("参数{}",ids);
        userService.deleteUser(ids);
        return Result.success();
    }

    //增加用户
    @PostMapping
    private Result addUser(@RequestBody User user){
        log.info("参数：{}",user);
        userService.addUser(user);
        return Result.success();
    }

    //用户信息回显
    @GetMapping("/{id}")
    public Result retUser(@PathVariable Integer id){
        User user = userService.retUser(id);
        return Result.success(user);
    }

    //修改用户信息
    @PutMapping
    public Result updateUser(@RequestBody User user){
        log.info("参数修改：{}",user);
        userService.updateUser(user);
        return Result.success();
    }
}
